package com.fulihui.usercore.core.processor.vcode;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Component;

import com.fulihui.usercore.enums.VcodeProcessTypeEnum;

/**
 * @author Created by Willard.Hu on 2016/6/4.
 */
@Component
public class VcodeProcessorRegistor extends ApplicationObjectSupport {
    private final transient Logger                    LOG          = LoggerFactory
                                                                       .getLogger(getClass());

    private Map<VcodeProcessTypeEnum, VcodeProcessor> processorMap = new HashMap<>();

    @PostConstruct
    public void init() {
        Map<String, VcodeProcessor> beans = getApplicationContext().getBeansOfType(
            VcodeProcessor.class);
        for (VcodeProcessor processor : beans.values()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("VcodeProcessor 实现类{}已注册", processor.getClass().getName());
            }
            processorMap.put(processor.getProcessType(), processor);
        }
    }

    public VcodeProcessor getProcessor(VcodeProcessTypeEnum processType) {
        return processorMap.get(processType);
    }
}
